<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a row as an array</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.sqlsrv-fetch-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlsrv_fetch_array</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_fetch_array</span> &mdash; <span class="dc-title">Returns a row as an array</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sqlsrv-fetch-array-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sqlsrv_fetch_array</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$fetchType</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code></span>
  ]]] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   Returns the next available row of data as an associative array, a numeric 
   array, or both (the default).
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.sqlsrv-fetch-array-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">stmt</code></dt>

     <dd>

      <p class="para">
       A statement resource returned by sqlsrv_query or sqlsrv_prepare.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">fetchType</code></dt>

     <dd>

      <p class="para">
       A predefined constant specifying the type of array to return. Possible 
       values are <strong><code>SQLSRV_FETCH_ASSOC</code></strong>, 
       <strong><code>SQLSRV_FETCH_NUMERIC</code></strong>, and 
       <strong><code>SQLSRV_FETCH_BOTH</code></strong> (the default).
      </p>
      <p class="para">
      A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a 
      result set with multiple columns of the same name.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">row</code></dt>

     <dd>

      <p class="para">
       Specifies the row to access in a result set that uses a scrollable cursor. 
       Possible values are <strong><code>SQLSRV_SCROLL_NEXT</code></strong>, 
       <strong><code>SQLSRV_SCROLL_PRIOR</code></strong>, <strong><code>SQLSRV_SCROLL_FIRST</code></strong>, 
       <strong><code>SQLSRV_SCROLL_LAST</code></strong>, <strong><code>SQLSRV_SCROLL_ABSOLUTE</code></strong> and, 
       <strong><code>SQLSRV_SCROLL_RELATIVE</code></strong> (the default). When this parameter 
       is specified, the <code class="parameter">fetchType</code> must be explicitly defined.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">offset</code></dt>

     <dd>

      <p class="para">
       Specifies the row to be accessed if the row parameter is set to
       <strong><code>SQLSRV_SCROLL_ABSOLUTE</code></strong> or
       <strong><code>SQLSRV_SCROLL_RELATIVE</code></strong>. Note that the first row in
       a result set has index 0.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-fetch-array-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an array on success, <strong><code>NULL</code></strong> if there are no more rows to return, and 
   <strong><code>FALSE</code></strong> if an error occurs.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.sqlsrv-fetch-array-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2576">
    <p><strong>Example #1 Retrieving an associative array.</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$serverName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"serverName\instanceName"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$serverName</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;FirstName,&nbsp;LastName&nbsp;FROM&nbsp;SomeTable"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;);<br />}<br /><br />while(&nbsp;</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_fetch_array</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLSRV_FETCH_ASSOC</span><span style="color: #007700">)&nbsp;)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'LastName'</span><span style="color: #007700">].</span><span style="color: #DD0000">",&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'FirstName'</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">sqlsrv_free_stmt</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2577">
    <p><strong>Example #2 Retrieving a numeric array.</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$serverName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"serverName\instanceName"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$serverName</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;FirstName,&nbsp;LastName&nbsp;FROM&nbsp;SomeTable"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;);<br />}<br /><br />while(&nbsp;</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_fetch_array</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLSRV_FETCH_NUMERIC</span><span style="color: #007700">)&nbsp;)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">].</span><span style="color: #DD0000">",&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">].</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">sqlsrv_free_stmt</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.sqlsrv-fetch-array-notes">
  <h3 class="title">注释</h3>
  <p class="para">
   Not specifying the <code class="parameter">fetchType</code> or explicity using the 
   <strong><code>SQLSRV_FETCH_TYPE</code></strong> constant in the examples above will 
   return an array that has both associative and numeric keys. 
  </p>
  <p class="para">
   If more than one column is returned with the same name, the last column will 
   take precedence. To avoid field name collisions, use aliases. 
  </p>
  <p class="para">
  If a column with no name is returned, the associative key for the array element 
  will be an empty string (&quot;&quot;).
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.sqlsrv-fetch-array-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="sqlsrv_connect.html" class="function" rel="rdfs-seeAlso">sqlsrv_connect()</a> - Opens a connection to a Microsoft SQL Server database</span></li>
    <li class="member"><span class="function"><a href="sqlsrv_query.html" class="function" rel="rdfs-seeAlso">sqlsrv_query()</a> - Prepares and executes a query</span></li>
    <li class="member"><span class="function"><a href="sqlsrv_errors.html" class="function" rel="rdfs-seeAlso">sqlsrv_errors()</a> - Returns error and warning information about the last SQLSRV operation performed</span></li>
    <li class="member"><span class="function"><a href="sqlsrv_fetch.html" class="function" rel="rdfs-seeAlso">sqlsrv_fetch()</a> - Makes the next row in a result set available for reading</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>